package licode.unisop.authcenter.adapter.web;

import licode.unisop.authcenter.application.executor.CenterPlatformQueryExecutor;
import licode.unisop.authcenter.application.info.*;
import licode.unisop.client.inter.HasAuthority;
import licode.unisop.provider.vo.SiPageResult;
import licode.unisop.provider.vo.SiPlatform;
import licode.unisop.provider.vo.SiUser;
import licode.unisop.types.AuthConst;
import licode.unisop.unilite.result.UniReturnResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 定义统一认证平台中心领域相关接口
 *
 * @author licode
 */
@Slf4j
@UniReturnResult
@RestController
@RequestMapping("/uni-center/v1/platform")
public class CenterPlatformQueryController extends CenterBaseController {
    @Resource
    private CenterPlatformQueryExecutor centerPlatformQueryExecutor;

    /**
     * 分页查询平台领域用户信息
     */
    @RequestMapping(value = "/user/query/page", method = RequestMethod.POST)
    @HasAuthority(roles= AuthConst.SYSTEM_ADMIN, permits = "plat:query")
    public SiPageResult<SiUser> queryUserPage(@RequestBody PlatUserQueryPageIn req) {
        return centerPlatformQueryExecutor.queryUserPage(req);
    }

    /**
     * 分页查询平台信息
     */
    @RequestMapping(value = "/query/page", method = RequestMethod.POST)
    @HasAuthority(roles=AuthConst.SYSTEM_ADMIN, permits = "plat:query")
    public SiPageResult<SiPlatform> queryPage(@RequestBody PlatformQueryPageIn req) {
        return centerPlatformQueryExecutor.queryPage(getAuthIn(), req);
    }

    /**
     * 分页查询平台信息
     */
    @RequestMapping(value = "/auth/query/page", method = RequestMethod.POST)
    @HasAuthority(roles=AuthConst.SYSTEM_ADMIN)
    public SiPageResult<SiPlatform> queryAuthPage(@RequestBody AuthPlatformQueryPageIn req) {
        return centerPlatformQueryExecutor.queryAuthPage(getAuthIn(), req);
    }

    /**
     * 查询平台信息
     */
    @RequestMapping(value = "/query/lookup", method = RequestMethod.POST)
    @HasAuthority(roles=AuthConst.SYSTEM_ADMIN, permits = "plat:query")
    public SiPlatform lookup(@RequestBody PlatformLookupIn req) {
        return centerPlatformQueryExecutor.lookup(req);
    }

    /**
     * 查询平台租户信息
     */
    @RequestMapping(value = "/tenant/query/lookup", method = RequestMethod.POST)
    @HasAuthority(roles=AuthConst.SYSTEM_ADMIN, permits = "plat:query")
    public SiPageResult<SiPlatform> queryTenantPage(@RequestBody PlatTenantQueryPageIn req) {
        return centerPlatformQueryExecutor.queryTenantPage(req);
    }

    /**
     * 查询平台产品信息
     */
    @RequestMapping(value = "/product/query/lookup", method = RequestMethod.POST)
    @HasAuthority(roles=AuthConst.SYSTEM_ADMIN, permits = "plat:query")
    public SiPageResult<SiPlatform> queryProductPage(@RequestBody PlatProductQueryPageIn req) {
        return centerPlatformQueryExecutor.queryProductPage(req);
    }

    /**
     * 查询平台应用信息
     */
    @RequestMapping(value = "/application/query/lookup", method = RequestMethod.POST)
    @HasAuthority(roles=AuthConst.SYSTEM_ADMIN, permits = "plat:query")
    public SiPageResult<SiPlatform> queryApplicationPage(@RequestBody PlatApplicationQueryPageIn req) {
        return centerPlatformQueryExecutor.queryApplicationPage(req);
    }
}
